/**
 * 静态物体类
 * 1. 地板
 */
import * as THREE from "./three.js/build/three.module.js";
import A3Actor from "./A3Actor.js";
import { createRigidBody, getMeshShape, isNull } from "./A3Common.js";

class A3Static extends A3Actor {

  name='static';

  update(){}

}

class A3Ground extends A3Static {

  name='ground';

  constructor( width, depth, height, color ) {

    super();

    width = isNull( width ) ? 10 : width;
    depth = isNull( depth ) ? 10 : depth;
    height = isNull( height ) ? .1 : height;
    color = isNull( color ) ? 0xcccccc : color;

    this.mass = 0;
    this.position.set( 0, -height * 0.5, 0 );
    this.quaternion.set( 0, 0, 0, 1 );
    this.inertia.set( 0, 0, 0 );

    this.threeObject = new THREE.Mesh( 
      new THREE.BoxGeometry( width, height, depth, 1, 1, 1 ),
      new THREE.MeshPhongMaterial( { color : color } ) );

    this.physicsShape = getMeshShape( this.threeObject );

    this.physicsBody = createRigidBody( 
      this.physicsShape, 
      this.mass, this.position, this.quaternion, this.inertia );

    this.width = width;
    this.depth = depth;
    this.height = height;
    
    this.enableShadow();

  }

  loadTexture( textureFile ) {

    this.textureLoader.load( textureFile, ( texture ) => {
  
      texture.wrapS = THREE.RepeatWrapping;
      texture.wrapT = THREE.RepeatWrapping;
      texture.repeat.set( this.width, this.depth );
      
      this.setTexture( texture );

    } );

  }

}

export {
  A3Ground,
}